<template>
  <view class="tab-content" id="tab-contents">
    <view
      @tap="getTabIndex(item, index)"
      v-for="(item, index) in tabList"
      :class="{ 'tab-item-active': tabIndex == item.id }"
      class="tab-item"
    >
      <view class="pay1">
        {{ item.name }}
      </view>
    </view>
    <view
      class="pay-line"
      :style="{
        left:
          (100 / tabList.length) * currentIndex +
          100 / tabList.length / 2 +
          '%',
      }"
    ></view>
  </view>
</template>

<script>
export default {
  props: {
    tabList: {
      type: Array,
      default: [
        {
          name: "受理中",
          id: 0,
        },
        {
          name: "已解决",
          id: 1,
        },
      ],
    },
    value: {
      type: String,
      default: "",
    },
  },
  computed: {
    tabIndex: {
      get() {
        return this.value;
      },
      set(news) {
        this.$emit("input", news);
      },
    },
    currentIndex: {
      get() {
        return this.tabList.findIndex((ite) => ite.id == this.tabIndex);
      },
      set(news) {},
    },
  },
  methods: {
    getTabIndex(value, index) {
      this.tabIndex = value.id;
      this.currentIndex = index;
    },
  },
};
</script>

<style lang="scss" scoped>
.tab-content {
  width: 100%;
  padding: 17rpx 0;
  box-sizing: border-box;
  background-color: #ffffff;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .tab-item {
    flex: 1;
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 30rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    .pay1 {
      font-size: 30rpx;
      color: #999;
    }
  }

  .tab-item-active {
    .pay1 {
      font-size: 36rpx;
      font-weight: bold;
      color: #333;
    }
  }
  .pay-line {
    width: 80rpx;
    height: 0rpx;
    border: 4rpx solid #2e45f3;
    background-color: #2e45f3;
    border-radius: 6rpx;
    position: absolute;
    bottom: 0;
    transform: translateX(-50%);
    transition: all 0.2s linear;
  }
}
</style>
